<template>
  <div class="alarmConfiguration zy-content">
    <search :columns="searchData" @getSearch="getSearch(arguments)"></search>
    <div class="list-layout mt16">
      <div class="btns clear">
        <span class="title">{{ $t('common.listInformation') }}</span>
      </div>
      <!-- 表格 -->
      <div class="tableContent">
        <Table
            class="resizable-table"
            border
            @on-column-width-resize="
						(a, b, c, d) => {
							onColumnWidthResize(a, b, c, d, 'logGet');
						}
					"
            :columns="logGetList"
            ellipsis
            ref="selection"
            stripe
            :data="dataArr"
        >
          <template slot-s cope="{ row }" slot="action">
            <span class="operationBtn" @click="handleClick1(row)">数据重推</span>
          </template>
        </Table>
      </div>
      <!-- 分页 -->
      <div class="pageWrap mt16">
        <pageLeftTitle :total="total" :selected="delIds.length"/>
        <Page
            :total="total"
            :page-size="pageSize"
            :page-size-opts="pageSizeOption"
            :current="pageNum"
            @on-change="changePageNum"
            @on-page-size-change="changePageSize"
            show-sizer
            show-total
        />
      </div>
    </div>
    <!-- 请确认是否删除弹框 -->
    <Modal :mask-closable="false" v-model="delFaultCodeShowF" title="数据重推" class="modal-title-layout">
      <p class="title">是否重新推送该业务</p>
      <div slot="footer">
        <Button type="default" @click="delFaultCodeShowF = false">
          {{ $t('common.Cancle') }}
        </Button>
        <Button type="primary" :loading="loading" @click="deleteOK">
          {{ $t('maintenance.Confirmed') }}
        </Button>
      </div>
    </Modal>
  </div>
</template>

<script>
import search from '@/components/curd/searchList.vue';
import toggleTableOperation from '@/mixins/toggleTableOperation';

export default {
  name: 'logPush',
  components: {search},
  mixins: [toggleTableOperation],
  data() {
    return {
      loading: false,
      create: false,
      searchParams: {},
      pageNum: 1,
      pageSize: 10,
      total: 0,
      searchData: [
        {
          title: '请求地址',
          // key: "handleResult"
          key: 'apiMethod',
        },
        {
          title: '请求者姓名',
          // key: "handleBusiness"
          key: 'realName',
        },
        {
          title: '请求报文',
          key: 'requestParams',
        },
        {
          title: '创建时间',
          key: 'time',
          type: 'daterange',
          span: 6,
          defaultTimeRange: 7,
          noreset: true,
          clearable: false,
        },

        // {
        //   title: "结束时间",
        //   // key: "time2",
        //   key: "creatEndTime",
        //   type: "daterange"
        // }
      ],
      columns: [
        {
          key: 'index',
          type: 'index',
          width: 60,
          align: 'center',
        },
        {
          title: '请求地址',
          // key: "handleBusiness",
          key: 'apiMethod',
          minWidth: 130,
          align: 'center',
          resizable: true,
          tooltip: true,
        },

        {
          title: '请求者ip',
          // key: "handleUrl",
          key: 'ipAddredd',
          minWidth: 130,
          align: 'center',
          resizable: true,
          tooltip: true,
        },
        {
          title: '请求者姓名',
          // key: "handleParam",
          key: 'realName',
          width: 130,
          align: 'center',
          resizable: true,
          tooltip: true,
        },
        {
          title: '请求报文',
          // key: "handleResult",
          key: 'requestParams',
          minWidth: 150,
          tooltip: true,
          align: 'center',
          resizable: true,
        },
        {
          title: '响应结果',
          // key: "flowTo",
          key: 'responseParams',
          minWidth: 130,
          align: 'center',
          resizable: true,
        },
        {
          title: '创建时间',
          // key: "createTime",
          key: 'creatTime',
          minWidth: 150,
          align: 'center',
          resizable: true,
        },
        {
          title: `${this.$t('common.operation')}`,
          slot: 'action',
          fixed: 'right',
          minWidth: 160,
          align: 'center',
        },
      ],
      dataArr: [],
      pageSizeOption: [10, 20, 30, 40],
      delIds: [],
      selection: [],
      delFaultCodeShowF: false,
      currentRow: {},
    };
  },
  mounted() {
    this.getTableColumnsWidth(this.columns, 'logGet');
    const today = new Date();
    const sevenDaysAgo = new Date();
    sevenDaysAgo.setDate(today.getDate() - 7);
    const ls = [today, sevenDaysAgo]
    this.searchParams = {
      creatStartTime:this.getFormattedDate(sevenDaysAgo),
      creatEndTime: this.getFormattedDate(today)
    }
    this.searchList();
  },
  methods: {
    getSearch(arg) {
      this.searchParams = JSON.parse(JSON.stringify(arg[0]));
      const {time} = this.searchParams;
      if (time && time.length == 2) {
        this.searchParams.creatStartTime = time[0];
        this.searchParams.creatEndTime = time[1];
        delete this.searchParams.time;
      }
      this.pageNum = 1;

      this.searchList();
    },
    getFormattedDate(date) {
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, '0');
      const day = String(date.getDate()).padStart(2, '0');
      return `${year}-${month}-${day}`;
    },
    handleClick1(row) {
      //点击展示提示删除弹窗
      this.delFaultCodeShowF = true;
      this.currentRow = row;
    },
    deleteOK() {
      this.delFaultCodeShowF = false;
      this.axios({
        url: '/dms/thirdPartyLog/rePush?id=' + this.currentRow.id,
        method: 'put',
      }).then((res) => {
        if (res.code === 200) {
          this.delFaultCodeShowF = false;
          this.$Message.success({
            content: res.msg,
            duration: 6,
            closable: true,
          });
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true,
          });
        }
      });
    },
    reset() {
      this.searchParams = {};
      this.changeNum();
    },
    //分页
    changeNum() {
      this.pageNum = 1;
      this.searchList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.searchList();
    },
    changePageNum(val) {
      this.pageNum = val;
      this.searchList();
    },
    //查询列表
    searchList() {
      let params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        ...this.searchParams,
      };
      this.axios({
        method: 'post',
        url: '/dms/apiMethodLog/page',
        data: params,
      }).then((res) => {
        if (res.code === 200) {
          this.dataArr = res.data.records;
          this.total = res.data.total;
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true,
          });
        }
      });
    },
  },
};
</script>

<style scoped lang="scss">
.ivu-input-number {
  width: -webkit-fill-available;
}

.row_click {
  cursor: pointer;
  color: rgb(50, 113, 240) !important;
}
</style>
